<template>
  <!-- 跟标签节点 -->
  <section>
    <!--工具条-->
    <el-col :span="24" class="toolbar" style="padding-bottom: 0px;">
      <el-form :inline="true" :model="query">
        <el-form-item>
          <el-input v-model="query.keywords" placeholder="商店名称"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" v-on:click="search">查询</el-button>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="handleAdd">新增</el-button>
        </el-form-item>
      </el-form>
    </el-col>


    <!--列表-->
    <el-table :data="dataList" highlight-current-row v-loading="listLoading" @selection-change="selsChange" style="width: 100%;">
      <el-table-column type="selection" width="55">
      </el-table-column>
      <el-table-column type="index" width="60">
      </el-table-column>
      <el-table-column prop="name" label="商店名字"  >
      </el-table-column>
      <el-table-column prop="tel" label="电话"  >
      </el-table-column>
      <el-table-column prop="registerTime" label="时间"  >
      </el-table-column>
      <el-table-column prop="state" label="编号(不知道)"  >
      </el-table-column>
      <el-table-column prop="address" label="地址"  >
      </el-table-column>
      <el-table-column prop="logo" label="图片"  >
      </el-table-column>


      <el-table-column label="操作" width="150">
        <template scope="scope">
          <el-button size="small" @click="handleEdit(scope.$index, scope.row)">编辑</el-button>
          <el-button type="danger" size="small" @click="handleDel(scope.$index, scope.row)">删除</el-button><br><br>
          <el-button type="danger" size="small" @click="auditing(scope.$index, scope.row)">审核</el-button>

        </template>
      </el-table-column>
    </el-table>


    <!--分页条-->
    <el-col :span="24" class="toolbar">
      <el-button type="danger" @click="batchRemove" :disabled="this.sels.length===0">批量删除</el-button>
      <el-pagination
          layout="total, sizes, prev, pager, next, jumper"
          @current-change="handleCurrentChange"
          :page-size="pageSize"
          :page-sizes="[5, 10, 20, 50]"
          @size-change="handleSizeChange"
          :total="total" style="float:right;">
      </el-pagination>
    </el-col>

    <!-- 添加和编辑的弹出框 -->
    <el-dialog :title="title" :visible.sync="formVisible" :close-on-click-modal="false">
      <el-form :model="roleForm" label-width="100px" :rules="roleFormRules" ref="roleForm">
        <el-form-item label="商品名字" prop="name">
          <el-input v-model="roleForm.name" auto-complete="off"></el-input>
        </el-form-item>
        <el-form-item label="电话" prop="name">
          <el-input v-model="roleForm.tel" auto-complete="off"></el-input>
        </el-form-item>
<!--        <el-form-item label="时间" prop="name">-->
<!--          <el-input v-model="roleForm.register" auto-complete="off"></el-input>-->
<!--        </el-form-item>-->
        <el-form-item label="编号(?)" prop="name">
          <el-input v-model="roleForm.state" auto-complete="off"></el-input>
        </el-form-item>
        <el-form-item label="地址" prop="name">
          <el-input v-model="roleForm.address" auto-complete="off"></el-input>
        </el-form-item>
        <el-form-item label="图片" prop="name">
          <el-input v-model="roleForm.logo" auto-complete="off"></el-input>
        </el-form-item>

      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click.native="formVisible = false">取消</el-button>
        <el-button type="primary" @click.native="formSubmit" :loading="roleFormLoading">提交</el-button>
      </div>
    </el-dialog>

    <!-- 审核的弹出框 -->
    <el-dialog :title="title2" :visible.sync="formVisible2" :close-on-click-modal="false">
      <el-form :model="roleForm" label-width="100px" :rules="roleFormRules" ref="roleForm">
        <el-form-item label="名称" prop="name">
          <el-input v-model="roleForm.name"  auto-complete="off" disabled></el-input>
        </el-form-item>
        <el-form-item label="电话" prop="name">
          <el-input v-model="roleForm.tel" auto-complete="off" disabled></el-input>
        </el-form-item>
                <el-form-item label="时间" prop="name">
                  <el-input v-model="roleForm.registerTime" auto-complete="off" disabled></el-input>
                </el-form-item>
        <el-form-item label="编号(?)" prop="name">
          <el-input v-model="roleForm.state" auto-complete="off" disabled></el-input>
        </el-form-item>
        <el-form-item label="地址" prop="name">
          <el-input v-model="roleForm.address" auto-complete="off" disabled></el-input>
        </el-form-item>
        <el-form-item label="图片" prop="name">
          <el-input v-model="roleForm.logo" auto-complete="off" disabled></el-input>
        </el-form-item>

      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click.native="formVisible2 = false">取消</el-button>
        <el-button type="success" @click.native="reject">驳回</el-button>
        <el-button type="primary" @click.native="adopt" :loading="roleFormLoading">通过</el-button>
      </div>
    </el-dialog>


    <!-- 驳回的弹出框 -->
    <el-dialog :title="title3" :visible.sync="formVisible3" :close-on-click-modal="false">
      <el-form :model="roleForm" label-width="100px" :rules="roleFormRules" ref="roleForm">
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        驳回类型&nbsp;&nbsp;&nbsp;
          <el-select v-model="value" placeholder="请选择" >
            <el-option
                v-for="item in options"


                :key="item.value"
                :label="item.label"
                :value="item.value">
            </el-option>
          </el-select>

          <br><br><br>

          <el-form-item label="详细描述" prop="name">
            <el-input v-model="rejecttext" auto-complete="off" ></el-input>
          </el-form-item>

      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click.native="formVisible3 = false">取消</el-button>
        <el-button type="primary" @click.native="rejectsu" :loading="roleFormLoading">提交</el-button>
      </div>
    </el-dialog>




  </section>

</template>

<script>
import util from "../../common/js/util";
import {addUser, batchRemoveUser} from "../../api/api";


export default {
  name:"Shop",
  data(){
    return {
      query:{
        keywords:null
      },
      dataList:[],
      listLoading:false,
      sels:[],
      total:0,
      currentPage: 1,
      pageSize:10,
      title:"新增",
      formVisible:false, //默认关闭弹出框 添加
      title2:"审核",
      formVisible2:false, //默认关闭弹出框 审核
      title3:"驳回",
      formVisible3:false, //默认关闭弹出框 驳回
      roleForm:{
        id:null,
        name:null,
        tel:null,
        registerTime:null,
        state:null,
        address:null,
        logo:null
      },
      roleFormRules: {
        name: [
          { required: true, message: '请输入角色名称', trigger: 'blur' }
        ]
      },
      roleFormLoading:false,
      permissionTree:[],
      defaultProps: {
        children: 'children',
        label: 'name'
      },

      options: [{
        value: 'logo图片不清楚',
        label: 'logo图片不清楚'
      }, {
        value: '店名违规',
        label: '店名违规'
      },
        {
        value: '清算账户问题',
        label: '清算账户问题'
      }],
      value: '',//驳回原因
      rejecttext:'',//驳回内容

    }//end
  },
  methods:{
    //驳回提交
    rejectsu(){
      // this.$refs.roleForm.validate((valid) => {
      //   if (valid) {//通过表单验证
          this.$confirm('确认提交数据吗？', '提示', {}).then(() => {
            //确认框 用户点击了确认
            this.roleFormLoading = true;

            let text={
              shop:this.roleForm,
              value:this.value,
              rejecttext:this.rejecttext
            }

            this.$http.put("/shop/reject",text).then((res) => {
              // console.log(123)
              if(res.data.success){
                // console.log(222)
                this.$message({
                  message: '提交成功',
                  type: 'success'


                });
              }else {
                this.$message.error(res.data.message);
              }
              //关闭弹出框
              this.formVisible3=false;
              this.formVisible2=false;
              this.loadListData();
              this.roleFormLoading = false;

            });
          });
        // }
      // });

    },
    //驳回
    reject(){
      this.formVisible3=true
    },
    //审核通过
    adopt(){

      this.$refs.roleForm.validate((valid) => {
        if (valid) {//通过表单验证
          this.$confirm('确认提交数据吗？', '提示', {}).then(() => {
            //确认框 用户点击了确认
            this.roleFormLoading = true;

            console.log(1)
            // this.$http.put("/shop/adopt",this.roleForm).then((res) => {
            this.$http.put("http://127.0.0.1:8081/shop/adopt",this.roleForm).then((res) => {
              console.log(2)
              if(res.data.success){
                this.$message({
                  message: '提交成功',
                  type: 'success'

                });
              }else {
                this.$message.error(res.data.message);
              }
              console.log(4)
              //关闭弹出框
              this.formVisible2=false;
              this.loadListData();
              this.roleFormLoading = false;

            });
          });
        }
      });

    },
    //审核
    auditing(index,row){

      //1.做数据的回显
      Object.assign(this.roleForm,row);
      //2.打开弹出框
      this.formVisible2=true;

      //3.查询当前角色拥有的数据权限 [1200,1201,1202]
      // this.loadPermissionIdByRoleId(row.id);
    },
    batchRemove(){
      //触发批量删除操作
      var ids = this.sels.map(item => item.id)
      this.$confirm('确认删除选中记录吗？', '提示', {
        type: 'warning'
      }).then(() => {
        this.listLoading = true;
        //NProgress.start();
        //let para = { ids: ids };
        this.$http.patch("/shop",ids).then((res) => {
          this.listLoading = false;
          //NProgress.done();
          this.$message({
            message: '删除成功',
            type: 'success'
          });
          this.loadListData();
        });
      }).catch(() => {

      });

    },

    //提交弹出框的效果
    formSubmit(){
      // console.debug()
      this.$refs.roleForm.validate((valid) => {
        if (valid) {//通过表单验证
          this.$confirm('确认提交数据吗？', '提示', {}).then(() => {
            //确认框 用户点击了确认
            this.roleFormLoading = true;
            // console.debug(this.$refs)
            //组装提交的数据

            // let param={
            //   shop:this.roleForm,
            //   permissionIds:this.$refs.tree.getCheckedKeys()
            // }

            this.$http.put("/shop",this.roleForm).then((res) => {
              // console.log(23124)
              if(res.data.success){
                this.$message({
                  message: '提交成功',
                  type: 'success'
                });
              }else {
                this.$message.error(res.data.message);
              }
              //关闭弹出框
              this.formVisible=false;
              this.loadListData();
              this.roleFormLoading = false;

            });
          });
        }
      });



    },


    search(){
      this.currentPage=1;
      this.loadListData();
    },
    handleAdd(){
      // console.debug(this.$refs)

      //1.清空表单数据
      this.roleForm={
        id:null,
        name:null,
        tel:null,
        registerTime:null,
        state:null,
        address:null,
        logo:null

      }
      //2.打开弹出框
      this.formVisible=true;

      //清空树形菜单
      this.$nextTick(()=>{
        this.$refs.tree.setCheckedKeys([]);
      })


    },
    selsChange(sels){
      console.debug(sels)
      this.sels=sels;
    },
    //性别显示转换
    formatState: function (row, column) {
      //console.debug(row)
      return row.state == 1 ? '启用' : '废弃';
    },

    loadPermissionIdByRoleId(id){
      this.$http.get("/shop/permsssion/"+id).then(res=>{
        this.$nextTick(()=>{
          this.$refs.tree.setCheckedKeys(res.data.data)
        })
      })

    }
    ,
    handleEdit(index,row){
      //1.做数据的回显
      Object.assign(this.roleForm,row);
      //2.打开弹出框
      this.formVisible=true;
      //3.查询当前角色拥有的数据权限 [1200,1201,1202]
      // this.loadPermissionIdByRoleId(row.id);
    },
    handleDel(index,row){
      this.$confirm('确认删除数据吗？', '提示', {
        type: 'warning'
      }).then(() => {
        //确认框 用户点击了确认
        this.$http.delete("/shop/"+row.id).then((res) => {

          if(res.data.success){
            this.$message({
              message: '删除成功',
              type: 'success'
            });
          }else {
            this.$message.error(res.data.message);
          }
          this.loadListData();
        });
      });
    },
    loadListData(){
      //加载列表数据
      this.listLoading=true
      //封装请求数据
      let query ={
        currentPage:this.currentPage,
        pageSize:this.pageSize,
        keywords:this.query.keywords
      }
      //发送请求获取列表数据
      this.$http.post("/shop",query).then(res=>{

        console.debug(res)
        this.dataList=res.data.data.data;
        this.total=res.data.data.count;
        //关闭加载效果
        this.listLoading=false;
      })
    },
    handleCurrentChange(num){
      this.currentPage=num;
      this.loadListData();
    },
    handleSizeChange(num){//当用户切换每页展示的条数的时候触发的方法
      this.pageSize=num;
      this.loadListData();
    },
    loadDepts(){
      //发送请求获取所有的员工
      this.$http.get("/dept").then(res=>{
        this.depts=res.data;
      })

    },
    loadPermissionTree(){//加载部门树
      this.$http.get("/permission/tree").then(res=>{
        this.permissionTree=res.data.data;
      })
    }

  },
  mounted() {
    this.loadListData();
    this.loadPermissionTree();


  }

}

</script>

<style scoped>

</style>
